<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>Admin站点 | 欢迎学习django课程</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../part5/6.html" />
    
    
    <link rel="prev" href="../part5/4.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="5.4"
        data-chapter-title="Admin站点"
        data-filepath="part5/5.md"
        data-basepath=".."
        data-revision="Tue Jan 03 2017 08:43:08 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        课程介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="part1/1.html">
            
                
                    <a href="../part1/1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        入门
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="part1/2.html">
            
                
                    <a href="../part1/2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        搭建开发环境
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="part1/3.html">
            
                
                    <a href="../part1/3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        设计模型
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="part1/4.html">
            
                
                    <a href="../part1/4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        管理站点
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="part1/5.html">
            
                
                    <a href="../part1/5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        视图
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="part1/6.html">
            
                
                    <a href="../part1/6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        模板
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="part1/7.html">
            
                
                    <a href="../part1/7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        总结与作业
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="part2/1.html">
            
                
                    <a href="../part2/1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        模型
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="part2/2.html">
            
                
                    <a href="../part2/2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        定义模型
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="part2/3.html">
            
                
                    <a href="../part2/3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        模型成员
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="part2/4.html">
            
                
                    <a href="../part2/4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        模型查询
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="part2/5.html">
            
                
                    <a href="../part2/5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        自连接
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="part2/6.html">
            
                
                    <a href="../part2/6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        总结与作业
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="part3/1.html">
            
                
                    <a href="../part3/1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        视图
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="part3/2.html">
            
                
                    <a href="../part3/2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        URLconf
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="part3/3.html">
            
                
                    <a href="../part3/3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        视图函数
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="part3/4.html">
            
                
                    <a href="../part3/4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        Request对象
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.3.1" data-path="part3/4_1.html">
            
                
                    <a href="../part3/4_1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.1.</b>
                        
                        QueryDict对象
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3.2" data-path="part3/4_2.html">
            
                
                    <a href="../part3/4_2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.2.</b>
                        
                        GET属性
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3.3" data-path="part3/4_3.html">
            
                
                    <a href="../part3/4_3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.3.</b>
                        
                        POST属性
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="part3/5.html">
            
                
                    <a href="../part3/5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        Response对象
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="part3/6.html">
            
                
                    <a href="../part3/6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.5.</b>
                        
                        状态保持
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="part3/7.html">
            
                
                    <a href="../part3/7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.6.</b>
                        
                        总结与作业
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" data-path="part4/1.html">
            
                
                    <a href="../part4/1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.</b>
                        
                        模板
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="part4/2.html">
            
                
                    <a href="../part4/2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        定义模板
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="part4/3.html">
            
                
                    <a href="../part4/3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        模板继承
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.3" data-path="part4/4.html">
            
                
                    <a href="../part4/4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.3.</b>
                        
                        HTML转义
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.4" data-path="part4/5.html">
            
                
                    <a href="../part4/5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.4.</b>
                        
                        CSRF
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.5" data-path="part4/6.html">
            
                
                    <a href="../part4/6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.5.</b>
                        
                        验证码
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.6" data-path="part4/7.html">
            
                
                    <a href="../part4/7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.6.</b>
                        
                        总结与作业
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="5" data-path="part5/1.html">
            
                
                    <a href="../part5/1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.</b>
                        
                        高级
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="5.1" data-path="part5/2.html">
            
                
                    <a href="../part5/2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.1.</b>
                        
                        静态文件处理
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.2" data-path="part5/3.html">
            
                
                    <a href="../part5/3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.2.</b>
                        
                        中间件
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.3" data-path="part5/4.html">
            
                
                    <a href="../part5/4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.3.</b>
                        
                        上传图片
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="5.4" data-path="part5/5.html">
            
                
                    <a href="../part5/5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.4.</b>
                        
                        Admin站点
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.5" data-path="part5/6.html">
            
                
                    <a href="../part5/6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.5.</b>
                        
                        分页
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.6" data-path="part5/7.html">
            
                
                    <a href="../part5/7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.6.</b>
                        
                        ajax
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="5.7" data-path="part5/8.html">
            
                
                    <a href="../part5/8.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>5.7.</b>
                        
                        总结与作业
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="6" data-path="part6/1.html">
            
                
                    <a href="../part6/1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.</b>
                        
                        第三方
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="6.1" data-path="part6/2.html">
            
                
                    <a href="../part6/2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.1.</b>
                        
                        富文本编辑器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.2" data-path="part6/3.html">
            
                
                    <a href="../part6/3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.2.</b>
                        
                        缓存
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.3" data-path="part6/4.html">
            
                
                    <a href="../part6/4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.3.</b>
                        
                        全文检索
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.4" data-path="part6/5.html">
            
                
                    <a href="../part6/5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.4.</b>
                        
                        celery
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.5" data-path="part6/6.html">
            
                
                    <a href="../part6/6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.5.</b>
                        
                        布署
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="6.6" data-path="part6/7.html">
            
                
                    <a href="../part6/7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>6.6.</b>
                        
                        总结与作业
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7" data-path="part7/1.html">
            
                
                    <a href="../part7/1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.</b>
                        
                        Git与项目
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1" data-path="part7/2.html">
            
                
                    <a href="../part7/2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.1.</b>
                        
                        Git简介
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="7.1.1" data-path="part7/2_2.html">
            
                
                    <a href="../part7/2_2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.1.1.</b>
                        
                        远程仓库
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.1.2" data-path="part7/2_1.html">
            
                
                    <a href="../part7/2_1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.1.2.</b>
                        
                        本地仓库
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="7.2" data-path="part7/3.html">
            
                
                    <a href="../part7/3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.2.</b>
                        
                        项目设计
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.3" data-path="part7/4.html">
            
                
                    <a href="../part7/4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.3.</b>
                        
                        模型类设计
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.4" data-path="part7/5.html">
            
                
                    <a href="../part7/5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.4.</b>
                        
                        使用页面
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="7.5" data-path="part7/6.html">
            
                
                    <a href="../part7/6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>7.5.</b>
                        
                        总结与作业
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >欢迎学习django课程</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="admin&#x7AD9;&#x70B9;">Admin&#x7AD9;&#x70B9;</h1>
<ul>
<li>&#x901A;&#x8FC7;&#x4F7F;&#x7528;startproject&#x521B;&#x5EFA;&#x7684;&#x9879;&#x76EE;&#x6A21;&#x7248;&#x4E2D;&#xFF0C;&#x9ED8;&#x8BA4;Admin&#x88AB;&#x542F;&#x7528;</li>
<li>1.&#x521B;&#x5EFA;&#x7BA1;&#x7406;&#x5458;&#x7684;&#x7528;&#x6237;&#x540D;&#x548C;&#x5BC6;&#x7801;</li>
</ul>
<pre><code>python manage.py createsuperuser
&#x7136;&#x540E;&#x6309;&#x63D0;&#x793A;&#x586B;&#x5199;&#x7528;&#x6237;&#x540D;&#x3001;&#x90AE;&#x7BB1;&#x3001;&#x5BC6;&#x7801;
</code></pre><ul>
<li>2.&#x5728;&#x5E94;&#x7528;&#x5185;admin.py&#x6587;&#x4EF6;&#x5B8C;&#x6210;&#x6CE8;&#x518C;&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x5728;&#x540E;&#x53F0;&#x7BA1;&#x7406;&#x4E2D;&#x7EF4;&#x62A4;&#x6A21;&#x578B;&#x7684;&#x6570;&#x636E;</li>
</ul>
<pre><code>from django.contrib import admin
from models import *

admin.site.register(HeroInfo)
</code></pre><ul>
<li>&#x67E5;&#x627E;admin&#x6587;&#x4EF6;&#xFF1A;&#x5728;INSTALLED_APPS&#x9879;&#x4E2D;&#x52A0;&#x5165;django.contrib.admin&#xFF0C;Django&#x5C31;&#x4F1A;&#x81EA;&#x52A8;&#x641C;&#x7D22;&#x6BCF;&#x4E2A;&#x5E94;&#x7528;&#x7684;admin&#x6A21;&#x5757;&#x5E76;&#x5C06;&#x5176;&#x5BFC;&#x5165;</li>
</ul>
<h1 id="modeladmin&#x5BF9;&#x8C61;">ModelAdmin&#x5BF9;&#x8C61;</h1>
<ul>
<li>ModelAdmin&#x7C7B;&#x662F;&#x6A21;&#x578B;&#x5728;Admin&#x754C;&#x9762;&#x4E2D;&#x7684;&#x8868;&#x793A;&#x5F62;&#x5F0F;</li>
<li>&#x5B9A;&#x4E49;&#xFF1A;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x7C7B;&#xFF0C;&#x7EE7;&#x627F;&#x4E8E;admin.ModelAdmin&#xFF0C;&#x6CE8;&#x518C;&#x6A21;&#x578B;&#x65F6;&#x4F7F;&#x7528;&#x8FD9;&#x4E2A;&#x7C7B;</li>
</ul>
<pre><code>class HeroAdmin(admin.ModelAdmin):
    ...
</code></pre><ul>
<li>&#x901A;&#x5E38;&#x5B9A;&#x4E49;&#x5728;&#x5E94;&#x7528;&#x7684;admin.py&#x6587;&#x4EF6;&#x91CC;</li>
<li>&#x4F7F;&#x7528;&#x65B9;&#x5F0F;&#x4E00;&#xFF1A;&#x6CE8;&#x518C;&#x53C2;&#x6570;</li>
</ul>
<pre><code>admin.site.register(HeroInfo,HeroAdmin)
</code></pre><ul>
<li>&#x4F7F;&#x7528;&#x65B9;&#x5F0F;&#x4E8C;&#xFF1A;&#x6CE8;&#x518C;&#x88C5;&#x9970;&#x5668;</li>
</ul>
<pre><code>@admin.register(HeroInfo)
class HeroAdmin(admin.ModelAdmin):
</code></pre><ul>
<li>&#x901A;&#x8FC7;&#x91CD;&#x5199;admin.ModelAdmin&#x7684;&#x5C5E;&#x6027;&#x89C4;&#x5B9A;&#x663E;&#x793A;&#x6548;&#x679C;&#xFF0C;&#x5C5E;&#x6027;&#x4E3B;&#x8981;&#x5206;&#x4E3A;&#x5217;&#x8868;&#x9875;&#x3001;&#x589E;&#x52A0;&#x4FEE;&#x6539;&#x9875;&#x4E24;&#x90E8;&#x5206;</li>
</ul>
<h4 id="&#x5217;&#x8868;&#x9875;&#x9009;&#x9879;">&#x5217;&#x8868;&#x9875;&#x9009;&#x9879;</h4>
<h6 id="&#x64CD;&#x4F5C;&#x9009;&#x9879;&#x7684;&#x4F4D;&#x7F6E;">&#x201C;&#x64CD;&#x4F5C;&#x9009;&#x9879;&#x201D;&#x7684;&#x4F4D;&#x7F6E;</h6>
<ul>
<li>actions_on_top&#x3001;actions_on_bottom&#xFF1A;&#x9ED8;&#x8BA4;&#x663E;&#x793A;&#x5728;&#x9875;&#x9762;&#x7684;&#x9876;&#x90E8;</li>
</ul>
<pre><code>class HeroAdmin(admin.ModelAdmin):
    actions_on_top = True
    actions_on_bottom = True
</code></pre><h6 id="listdisplay">list_display</h6>
<ul>
<li>&#x51FA;&#x73B0;&#x5217;&#x8868;&#x4E2D;&#x663E;&#x793A;&#x7684;&#x5B57;&#x6BB5;</li>
<li>&#x5217;&#x8868;&#x7C7B;&#x578B;</li>
<li>&#x5728;&#x5217;&#x8868;&#x4E2D;&#xFF0C;&#x53EF;&#x4EE5;&#x662F;&#x5B57;&#x6BB5;&#x540D;&#x79F0;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x662F;&#x65B9;&#x6CD5;&#x540D;&#x79F0;&#xFF0C;&#x4F46;&#x662F;&#x65B9;&#x6CD5;&#x540D;&#x79F0;&#x9ED8;&#x8BA4;&#x4E0D;&#x80FD;&#x6392;&#x5E8F;</li>
<li>&#x5728;&#x65B9;&#x6CD5;&#x4E2D;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;format_html()&#x8F93;&#x51FA;html&#x5185;&#x5BB9;</li>
</ul>
<pre><code>&#x5728;models.py&#x6587;&#x4EF6;&#x4E2D;
from django.db import models
from tinymce.models import HTMLField
from django.utils.html import format_html

class HeroInfo(models.Model):
    hname = models.CharField(max_length=10)
    hcontent = HTMLField()
    isDelete = models.BooleanField()
    def hContent(self):
        return format_html(self.hcontent)

&#x5728;admin.py&#x6587;&#x4EF6;&#x4E2D;
class HeroAdmin(admin.ModelAdmin):
    list_display = [&apos;hname&apos;, &apos;hContent&apos;]
</code></pre><ul>
<li>&#x8BA9;&#x65B9;&#x6CD5;&#x6392;&#x5E8F;&#xFF0C;&#x4E3A;&#x65B9;&#x6CD5;&#x6307;&#x5B9A;admin_order_field&#x5C5E;&#x6027;</li>
</ul>
<pre><code>&#x5728;models.py&#x4E2D;HeroInfo&#x7C7B;&#x7684;&#x4EE3;&#x7801;&#x6539;&#x4E3A;&#x5982;&#x4E0B;&#xFF1A;
    def hContent(self):
        return format_html(self.hcontent)
    hContent.admin_order_field = &apos;hname&apos;
</code></pre><ul>
<li>&#x6807;&#x9898;&#x680F;&#x540D;&#x79F0;&#xFF1A;&#x5C06;&#x5B57;&#x6BB5;&#x5C01;&#x88C5;&#x6210;&#x65B9;&#x6CD5;&#xFF0C;&#x4E3A;&#x65B9;&#x6CD5;&#x8BBE;&#x7F6E;short_description&#x5C5E;&#x6027;</li>
</ul>
<pre><code>&#x5728;models.py&#x4E2D;&#x4E3A;HeroInfo&#x7C7B;&#x589E;&#x52A0;&#x65B9;&#x6CD5;hName&#xFF1A;
    def hName(self):
        return self.hname
    hName.short_description = &apos;&#x59D3;&#x540D;&apos;
    hContent.short_description = &apos;&#x5185;&#x5BB9;&apos;

&#x5728;admin.py&#x9875;&#x4E2D;&#x6CE8;&#x518C;
class HeroAdmin(admin.ModelAdmin):
    list_display = [&apos;hName&apos;, &apos;hContent&apos;]
</code></pre><h6 id="listfilter">list_filter</h6>
<ul>
<li>&#x53F3;&#x4FA7;&#x680F;&#x8FC7;&#x6EE4;&#x5668;&#xFF0C;&#x5BF9;&#x54EA;&#x4E9B;&#x5C5E;&#x6027;&#x7684;&#x503C;&#x8FDB;&#x884C;&#x8FC7;&#x6EE4;</li>
<li>&#x5217;&#x8868;&#x7C7B;&#x578B;</li>
<li>&#x53EA;&#x80FD;&#x63A5;&#x6536;&#x5B57;&#x6BB5;</li>
</ul>
<pre><code>class HeroAdmin(admin.ModelAdmin):
    ...
    list_filter = [&apos;hname&apos;, &apos;hcontent&apos;]
</code></pre><h6 id="listperpage">list_per_page</h6>
<ul>
<li>&#x6BCF;&#x9875;&#x4E2D;&#x663E;&#x793A;&#x591A;&#x5C11;&#x9879;&#xFF0C;&#x9ED8;&#x8BA4;&#x8BBE;&#x7F6E;&#x4E3A;100</li>
</ul>
<pre><code>class HeroAdmin(admin.ModelAdmin):
    ...
    list_per_page = 10
</code></pre><h6 id="searchfields">search_fields</h6>
<ul>
<li>&#x641C;&#x7D22;&#x6846;</li>
<li>&#x5217;&#x8868;&#x7C7B;&#x578B;&#xFF0C;&#x8868;&#x793A;&#x5728;&#x8FD9;&#x4E9B;&#x5B57;&#x6BB5;&#x4E0A;&#x8FDB;&#x884C;&#x641C;&#x7D22;</li>
<li>&#x53EA;&#x80FD;&#x63A5;&#x6536;&#x5B57;&#x6BB5;</li>
</ul>
<pre><code>class HeroAdmin(admin.ModelAdmin):
    ...
    search_fields = [&apos;hname&apos;]
</code></pre><h4 id="&#x589E;&#x52A0;&#x4E0E;&#x4FEE;&#x6539;&#x9875;&#x9009;&#x9879;">&#x589E;&#x52A0;&#x4E0E;&#x4FEE;&#x6539;&#x9875;&#x9009;&#x9879;</h4>
<ul>
<li>fields&#xFF1A;&#x663E;&#x793A;&#x5B57;&#x6BB5;&#x7684;&#x987A;&#x5E8F;&#xFF0C;&#x5982;&#x679C;&#x4F7F;&#x7528;&#x5143;&#x7EC4;&#x8868;&#x793A;&#x663E;&#x793A;&#x5230;&#x4E00;&#x884C;&#x4E0A;</li>
</ul>
<pre><code>class HeroAdmin(admin.ModelAdmin):
    ...
    fields = [(&apos;hname&apos;, &apos;hcontent&apos;)]
</code></pre><ul>
<li>fieldsets&#xFF1A;&#x5206;&#x7EC4;&#x663E;&#x793A;</li>
</ul>
<pre><code>class HeroAdmin(admin.ModelAdmin):
    ...
    fieldsets = (
        (&apos;base&apos;, {&apos;fields&apos;: (&apos;hname&apos;)}),
        (&apos;other&apos;, {&apos;fields&apos;: (&apos;hcontent&apos;)})
    )
</code></pre><ul>
<li>fields&#x4E0E;fieldsets&#x4E24;&#x8005;&#x9009;&#x4E00;</li>
</ul>
<h1 id="inlinemodeladmin&#x5BF9;&#x8C61;">InlineModelAdmin&#x5BF9;&#x8C61;</h1>
<ul>
<li>&#x7C7B;&#x578B;InlineModelAdmin&#xFF1A;&#x8868;&#x793A;&#x5728;&#x6A21;&#x578B;&#x7684;&#x6DFB;&#x52A0;&#x6216;&#x4FEE;&#x6539;&#x9875;&#x9762;&#x5D4C;&#x5165;&#x5173;&#x8054;&#x6A21;&#x578B;&#x7684;&#x6DFB;&#x52A0;&#x6216;&#x4FEE;&#x6539;</li>
<li>&#x5B50;&#x7C7B;TabularInline&#xFF1A;&#x4EE5;&#x8868;&#x683C;&#x7684;&#x5F62;&#x5F0F;&#x5D4C;&#x5165;</li>
<li>&#x5B50;&#x7C7B;StackedInline&#xFF1A;&#x4EE5;&#x5757;&#x7684;&#x5F62;&#x5F0F;&#x5D4C;&#x5165;</li>
</ul>
<pre><code>class HeroInline(admin.TabularInline):
    model = HeroInfo

class BookAdmin(admin.ModelAdmin):
    inlines = [
        HeroInline,
    ]
</code></pre><h1 id="&#x91CD;&#x5199;admin&#x6A21;&#x677F;">&#x91CD;&#x5199;admin&#x6A21;&#x677F;</h1>
<ul>
<li>&#x5728;&#x9879;&#x76EE;&#x6240;&#x5728;&#x76EE;&#x5F55;&#x4E2D;&#x521B;&#x5EFA;templates&#x76EE;&#x5F55;&#xFF0C;&#x518D;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;admin&#x76EE;&#x5F55;</li>
<li>&#x8BBE;&#x7F6E;&#x6A21;&#x677F;&#x67E5;&#x627E;&#x76EE;&#x5F55;&#xFF1A;&#x4FEE;&#x6539;settings.py&#x7684;TEMPLATES&#x9879;&#xFF0C;&#x52A0;&#x8F7D;&#x6A21;&#x677F;&#x65F6;&#x4F1A;&#x5728;DIRS&#x5217;&#x8868;&#x6307;&#x5B9A;&#x7684;&#x76EE;&#x5F55;&#x4E2D;&#x641C;&#x7D22;</li>
</ul>
<pre><code>&apos;DIRS&apos;: [os.path.join(BASE_DIR, &apos;templates&apos;)],
</code></pre><ul>
<li>&#x4ECE;Django&#x5B89;&#x88C5;&#x7684;&#x76EE;&#x5F55;&#x4E0B;&#xFF08;django/contrib/admin/templates&#xFF09;&#x5C06;&#x6A21;&#x677F;&#x9875;&#x9762;&#x7684;&#x6E90;&#x6587;&#x4EF6;admin/base_site.html&#x62F7;&#x8D1D;&#x5230;&#x7B2C;&#x4E00;&#x6B65;&#x5EFA;&#x597D;&#x7684;&#x76EE;&#x5F55;&#x91CC;</li>
<li>&#x7F16;&#x8F91;base_site.html&#x6587;&#x4EF6;</li>
<li>&#x5237;&#x65B0;&#x9875;&#x9762;&#xFF0C;&#x53D1;&#x73B0;&#x4EE5;&#x521A;&#x624D;&#x7F16;&#x8F91;&#x7684;&#x9875;&#x9762;&#x6548;&#x679C;&#x663E;&#x793A;</li>
<li>&#x5176;&#x5B83;&#x7BA1;&#x7406;&#x540E;&#x53F0;&#x7684;&#x6A21;&#x677F;&#x53EF;&#x4EE5;&#x6309;&#x7167;&#x76F8;&#x540C;&#x7684;&#x65B9;&#x5F0F;&#x8FDB;&#x884C;&#x4FEE;&#x6539;</li>
</ul>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../part5/4.html" class="navigation navigation-prev " aria-label="Previous page: 上传图片"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../part5/6.html" class="navigation navigation-next " aria-label="Next page: 分页"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
